package com.paireach.szwolaiyun.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

import com.paireach.szwolaiyun.R;
import com.paireach.szwolaiyun.sz_common_widget.activity.BaseActivity;
import com.paireach.szwolaiyun.sz_util.SharedPreferencesUtil;
import com.paireach.szwolaiyun.util.MessageInfoUtil;

import cn.jpush.android.api.JPushInterface;

public class WelcomeActivity extends BaseActivity {


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);


        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000);
                    if (SharedPreferencesUtil.isLogin(WelcomeActivity.this)) {
                        handler.sendEmptyMessage(MessageInfoUtil.AUTOMATIC_LOGIN);
                    } else {
                        handler.sendEmptyMessage(MessageInfoUtil.WEL_TO_LOGIN);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }
            }
        }).start();
    }

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case MessageInfoUtil.AUTOMATIC_LOGIN:
                    startActivity(new Intent(WelcomeActivity.this, MainActivity.class));
                    finish();
                    break;
                case MessageInfoUtil.WEL_TO_LOGIN:
                    startActivity(new Intent(WelcomeActivity.this, LoginActivity.class));
                    finish();
                    break;
            }

        }
    };

    @Override
    protected void onPause() {
        super.onPause();
        JPushInterface.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        JPushInterface.onResume(this);
    }
}
